﻿@{
    ViewBag.Title = "Group";
    Layout = null;
}
@using DDit.Core.Data.SystemEntity.Entity;
@using DDitApplicationFrame.Common;
@Styles.Render("~/Scripts/bootstrap/css/1", "~/Scripts/datatables/css/1", "~/Content/1", "~/Scripts/alertjs/themes/1", "~/Scripts/select2/css/1", "~/Scripts/iconpicker/css/1", "~/Scripts/fancyTree/skin-win7/1", "~/Scripts/fileUpload/1")
@Scripts.Render("~/bundles/js")

<script type="text/javascript">
    $(function () {
        //初始化表格配置
        var table = $('#userTable').custromTable({
            ajax: {
                url: "/WxUser/GetGroupList",
                data: function (d) {
                    d.name = $("#nickname").val();
                    return JSON.stringify(d);
                }
            },
            columns: [
                { data: 'id', title: "编号" },
                { data: 'name', title: "名称" },
                { data: 'count', title: "关注人数" }
            ],
            buttons: [
                "btnClose",
                "btnOpen"
            ]
        });
        //新增或修改确认按钮
        var confrimBtn = function (index) {
            var openid = parent.$("#openid").val();
            var userForm = parent.$("#Userform");
            if (userForm.valid()) {
                var loading = parent.layer.load(2);
                userForm.ajaxSubmit({
                    dataType: "json",
                    success: function (data) {
                        parent.layer.close(loading);
                        if (data.result) {
                            parent.layer.close(index); //隐藏弹出
                            table.ajax.reload(null, openid == "" ? true : false);
                            alertify.success("操作成功！"); //弹出消息日志
                        } else {
                            alertify.error(data.message);
                        }
                    },
                    error: function (data) {
                        parent.layer.close(loading);
                        var obj = eval('(' + data.responseText + ')');
                        alertify.error(obj.message);
                    }
                });
            }
        }

        var openCreateUserLayer = function () {
            mainLayer = parent.layer.open({
                type: 1,
                title: "新增用户组",
                area: ['400px', '200px'],
                closeBtn: 1,
                shadeClose: false,
                skin: 'layerStyle',
                content: $("#wxuserLayer").html(),
                btn: [dditConfig.btn.close, dditConfig.btn.comfrie],
                yes: function (index, layero) {
                    confrimBtn(index);
                },
                success: function (i, l) {
                    parent.$("#Userform").FromEvent(function () {

                    });
                }
            });
        }
        //新增按钮操作
        $("#wxgroupCreate").click(function () {
            openCreateUserLayer();
        });
        //编辑按钮操作
        $("#wxgroupEdit").click(function () {
            var cc = table.rows('.selected')
            if (cc[0].length > 0) {
                var model = cc.data();         // 得到操作的实体
                openCreateUserLayer();
                parent.$("#Userform").setForm(model[0]);  //给表单赋值
                parent.$("#name").val(model[0].name);
                parent.layer.title("编辑用户组", mainLayer)
            } else {
                alertify.log("请选择一条操作信息！");
            }
        });
        //删除按钮操作
        $("#wxgroupDelete").click(function () {
            var cc = table.rows('.selected')
            if (cc[0].length > 0) {
                var model = cc.data();
                parent.layer.confirm("确定要删除该信息吗！", dditConfig.hintLayer, function () {
                    $.post("/WxUser/RemoveGroup", { id: model[0].id }, function (data) {
                        if (data.result) {
                            cc.remove().draw(false);
                            parent.layer.close(parent.layer.index);
                            alertify.success("删除成功！");
                        } else {
                            alertify.error(data.message);
                        }
                    });
                });
            } else {
                alertify.log("请选择一条操作信息！");
            }
        });


    })

</script>

<div class="margin w100f xoverhide">
    <div class="panel panel-default" style="margin-top: 10px">
        @Html.Action("CreateButtonByMuen", "Button", new { menuId = 32, mark = "wxgroup" })

    </div>
    <table id="userTable" class="table table-bordered table-striped w100f" cellspacing="0"></table>
</div>

<div id="wxuserLayer" class="displayn">
    <form class="form-horizontal formPadding" id="Userform" method="post" action="/WxUser/AddorEditGroup">
        @Html.Hidden("id")
        <div class="form-group">
            <label for="UserReallyname" class="col-sm-2 control-label labsty">昵称<span style="color:red">*</span></label>
            <div class="col-sm-6">
                <input type="text" class="form-control" name="name" maxlength="10" id="name" placeholder="组名称">
            </div>
        </div>
    </form>
</div>